/*
 *      Author: Guannan Ma
 *      @mythmgn
 *      Whatever license applied
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "base.h"

#ifndef BASE_LIB_LIBTIME_H
#define BASE_LIB_LIBTIME_H

#ifdef __cplusplus
extern "C"
{
#endif

#define MIN_OF_TIMER               0
#define HOUR_OF_TIMER              1
#define DAY_OF_MON_OF_TIMER        2
#define MON_OF_YEAR_OF_TIMER       3
#define DAY_OF_WEEK_OF_TIMER       4

#define JANUARY     0
#define FEBRARY     1
#define MARCH       2
#define APRIL       3
#define MAY         4
#define JUNE	    5
#define JULY	    6
#define AUGUEST	    7
#define	SEPTEMBER   8
#define OCTOBER		9
#define NOVEMBER	10
#define DECEMBER 	11

/*!
  min hour mon mday weekday

*/
#define WEEKDAYS   "* * * * 1-5"
#define WEEKENDS   "* * * * 0,6"
#define SUNDAYS    "* * * * 0"
#define MONDAYS    "* * * * 1"
#define TUESDAYS   "* * * * 2"
#define WEDNESDAYS "* * * * 3"
#define THURSDAYS  "* * * * 4"
#define FRIDAYS    "* * * * 5"
#define SATURDAYS  "* * * * 6"

/*
typedef struct timerDIY {
    char* strTime[MAX_NUMBER_OF_TIMERDIY];
    unsigned int length;
    unsigned int nextSec;
    time_t lastrun;
    dLinkList* dlinks[MAX_NUMBER_OF_TIMERDIY][5];
} timerDIY;
*/

BOOL getStrTimeNow(char *strNow,time_t *p_tt);
time_t getUTCNow();

/*timerDIY *initTimerDIY();
BOOL addTimerStr(timerDIY *p_tdiy,char *timerStr);
BOOL emptyTimerStr(timerDIY *p_tdiy);
unsigned long getNextWaitSecs(timerDIY *tmr, time_t t_now);
BOOL closeTimerDIY(timerDIY *p_tdiy);
*/

/*!
   tm_sec    The number of seconds after the minute, normally in the range
             0 to 59, but can be up to 60 to allow for leap seconds.

   tm_min    The number of minutes after the hour, in the range 0 to 59.

   tm_hour   The number of hours past midnight, in the range 0 to 23.

   tm_mday   The day of the month, in the range 1 to 31.

!!!    tm_mon    The number of months since January, in the range 0 to 11.

!!!    tm_year   The number of years since 1900.

!!!    tm_wday   The number of days since Sunday, in the range 0 to 6.

   tm_yday   The number of days since January 1, in the range 0 to 365.

   tm_isdst  A  flag  that  indicates  whether  daylight saving time is in
             effect at the time described.  The value is positive if  day‐
             light  saving time is in effect, zero if it is not, and nega‐
             tive if the information is not available.
*/

struct base_timer{
    uint64 start;
    uint64 end;
    uint8 is_run;
    void *extra_info;
    uint32 extra_size;
};

#if defined __linux__
inline uint64 get_cpu_hz();
BOOL start_timer(struct base_timer *pt);
BOOL stop_timer(struct base_timer *pt);
BOOL is_timer_run();
double get_passed_ms(const struct base_timer *pt);
double get_passed_sec(const struct base_timer *pt);
int milisleep(uint64 mili_sec);
#endif

#ifdef __cplusplus
}
#endif

#endif // LIB_TIME_H_INCLUDED
